package com.zx.www.volunteersystem.controller;

import com.zx.www.volunteersystem.mapper.Volunteer_infoMapper;
import com.zx.www.volunteersystem.pojo.Volunteer_info;
import com.zx.www.volunteersystem.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/volunteer_info")
@Tag(name = "志愿者信息管理")
public class Volunteer_infoController {
    @Resource
    private Volunteer_infoMapper volunteer_infoMapper;

    // 查询所有志愿者信息
    @GetMapping("/queryAll")
    @Operation(summary = "查询所有志愿者信息")
    public R queryAll(){
        return R.ok(volunteer_infoMapper.queryAll());
    }

    // 根据ID查询志愿者信息
    @GetMapping("/queryById/{id}")
    @Operation(summary = "根据ID查询志愿者信息")
    public R queryById(@PathVariable("id") Integer id){
        return R.ok(volunteer_infoMapper.queryById(id));
    }

    // 新增志愿者信息
    @PostMapping("/add")
    @Operation(summary = "新增志愿者信息")
    public R add(@RequestBody Volunteer_info volunteerInfo){
        int result = volunteer_infoMapper.insert(volunteerInfo);
        if(result > 0){
            return R.ok();
        }
        return R.error();
    }

    // 更新志愿者信息
    @PutMapping("/update")
    @Operation(summary = "更新志愿者信息")
    public R update(@RequestBody Volunteer_info volunteerInfo){
        int result = volunteer_infoMapper.update(volunteerInfo);
        if(result > 0){
            return R.ok();
        }
        return R.error();
    }

    // 删除志愿者信息
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除志愿者信息")
    public R delete(@PathVariable("id") Integer id){
        int result = volunteer_infoMapper.deleteById(id);
        if(result > 0){
            return R.ok();
        }
        return R.error();
    }
}
